﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ccit.OA.Utils;
using Ccit.OA.MsQuestion;

namespace Ccit.OA.Question
{
    public partial class qst_manage_View : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                _hidsRecid.Value = (null != Request.QueryString["Id"]) ? Request.QueryString["Id"].ToString() : "0";
                _hidRecId.Value = (null != Request.QueryString["Id"]) ? Request.QueryString["Id"].ToString() : "0";
                InitPage();
            }

        }
        private void InitPage()
        {
            if (_hidsRecid.Value != "0")
            {
                QuestionBLL Bll = new QuestionBLL();
                MsQuestionMes msMes = Bll.GetQuestions(_hidsRecid.Value.ToString());
                if (msMes != null)
                { 
                    string range = SysInterface.GetNameStrByIdStr(msMes.range, msMes.rangemark, ",");
                    string PubRange = SysInterface.GetNameStrByIdStr(msMes.pubrange, msMes.pubrangemark, ",");
                    txtRanage.Text = (range!="")?range:"&nbsp;";
                    txtPubRange.Text = (PubRange!="")?PubRange:"&nbsp;";
                    txtTitle.Text = (msMes.title!="")?msMes.title:"&nbsp;";
                    txtEndtime.Text = (msMes.endtime!="")?msMes.endtime:"&nbsp;";
                    txtExplain.Text = (msMes.explain!="")?msMes.explain:"&nbsp;";
                    radioType.Text = (msMes.type=="0")?"匿名":"实名";
                }
                Bll = null;
                BindTable();
            }
        }
        private void BindTable()
        {
            QuestionBLL Bll = new QuestionBLL();
            DataSet dSet = Bll.GetQuestion(_hidsRecid.Value.ToString(), "2");
            int iLine = 0;
            if (dSet.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dSet.Tables[0].Rows.Count; i++)
                {
                    DataRow iRow = dSet.Tables[0].Rows[i];
                    if (iRow["Qst_A2_10"].ToString() != "")
                    {
                        CreateTable(iLine, iRow, Bll);
                        iLine++;
                    }
                }
            }
            Bll = null;
        }

        private void CreateTable(int iLine, DataRow iRow, QuestionBLL Bll)
        {

            HtmlTableRow oRow = new HtmlTableRow();
            oRow.ID = "row_" + iLine.ToString();
            oRow.Attributes["class"] = "listrow2";

            HtmlTableCell oCellM = new HtmlTableCell();
            oCellM.Align = "center";
            oCellM.Attributes["class"] = "listcellrow";
            oCellM.Attributes["width"] = "30%";
            oCellM.InnerHtml = iRow["Qst_A2_30"].ToString();
            oRow.Cells.Add(oCellM);

            HtmlTableCell oCellX = new HtmlTableCell();
            oCellX.Align = "center";
            oCellX.Attributes["class"] = "listcellrow";
            oCellX.Attributes["width"] = "8%";
            oCellX.InnerHtml = (iRow["Qst_A2_50"].ToString() == "0") ? "单选" : "多选";
            oRow.Cells.Add(oCellX);

            HtmlTableCell oCellS = new HtmlTableCell();
            oCellS.Align = "center";
            oCellS.Attributes["class"] = "listcellrow";
            oCellS.Attributes["width"] = "10%";
            oCellS.InnerHtml = (iRow["Qst_A2_60"].ToString() == "0") ? "不可输入" : "可输入";
            oRow.Cells.Add(oCellS);

            string qId = (iRow["Qst_A2_10"].ToString() != "") ? iRow["Qst_A2_10"].ToString() : "0";
            string iNum = Bll.GetQuestionInfo(qId);
            HtmlTableCell oCellXX = new HtmlTableCell();
            oCellXX.Align = "center";
            oCellXX.Attributes["class"] = "listcellrow";
            oCellXX.Attributes["width"] = "28%";
            oCellXX.InnerHtml = iNum;
            oRow.Cells.Add(oCellXX); 
            tbProduct.Rows.Add(oRow);
        }
    }
}
